package com.javatest.demo.controller;

import com.javatest.demo.entities.Student;
import com.javatest.demo.service.DbService;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author liuziyang
 * @create 2020-06-20 16:44
 */
@RequestMapping("/student")
@RestController
public class StudentController {

    @Autowired
    private DbService dbService;

    @GetMapping("/getAll")
    public List<Student> getAllStudent() {
        return dbService.getAllStudent();
    }

    @PostMapping("/addStu")
    public void addNewOne(@RequestParam("name") String name, @RequestParam("age") int age, @RequestParam("school") String school) {
        Student student = new Student(name, age, school);
        dbService.addNewStudent(student);
    }
}
